/**
 * 
 */
package com.estock.common.model.security;

import javax.persistence.MappedSuperclass;
import javax.persistence.Transient;

import com.estock.common.util.StringUtil;

/**
 * @author richard
 *
 */
@MappedSuperclass
public abstract class Security extends BaseEntity {

	private static final long serialVersionUID = -9133017120409045852L;
	
	protected String code;
	protected String name;
	protected String abbr;
	
	public Security(String code, String name) {
		this.code = code;
		this.name = name;
	}

	public Security() {
	}
	
	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public String getAbbr() {
		return abbr;
	}

	public void setAbbr(String abbr) {
		this.abbr = abbr;
	}

	public abstract void setYesterPrice(float yesterdayPrice);
	
	public abstract void setLatestPrice(float latestPrice);

	@Transient
	public abstract float getYesterPrice();

	@Transient
	public abstract float getLatestPrice();

	@Transient
	public String getChangePct() {
		float ratio =  (getLatestPrice() - getYesterPrice()) / getYesterPrice();
		return StringUtil.formatFloat(ratio * 100, 2);
	}
	
	@Transient
	public String getLatestPriceStr() {
		return StringUtil.formatFloat(getLatestPrice(), 2);
	}
	
}
